package com.wn.class30.cotroller.shoppingmall;

import com.wn.class30.entity.Product;
import com.wn.class30.entity.Producttype;
import com.wn.class30.service.WXProductService;
import com.wn.class30.service.WXProductTypeService;
import com.wn.class30.tools.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping(value = "/weixin")
@Api(value = "商品分类",tags = "商品分类")
public class WXProductTypeController {
    @Resource
    private WXProductTypeService wxProductTypeService;
    @Resource
    private WXProductService wxProductService;
        @ApiOperation(value="所有商品分类",notes ="所有商品分类" )
        @GetMapping(value = "/queryAllProduct")
    public Result queryAllProduct(){
            List<Producttype> producttypes = wxProductTypeService.queryAll();
            System.out.println("---------"+producttypes.get(1).getProductList().get(0).getProductName());
            return new Result("200","success",null,producttypes);
        }
        @GetMapping(value="/shop/queryProductByXiaoliang")
        @ApiOperation(value="根据销量降序查询",notes ="根据销量降序查询" )
        public Result queryProductByXiaoliang(String productSearch,Integer productTypeid){
            List<Product> products=null;
               if(productSearch==null){
                    products = wxProductService.queryProductByOrderandType(productTypeid,"product_sales desc");
               }else{
                   products = wxProductService.queryProductByOrderandSerach(productSearch,"product_sales desc");
               }
               return new Result("200","success",null,products);
        }
    @GetMapping(value="/shop/queryProductByJiaGe")
    @ApiOperation(value="根据价格升序查询",notes ="根据价格升序查询" )
        public Result queryProductByJiaGe(String productSearch,Integer productTypeid){
        List<Product> products=null;
        if(productSearch==null){
            products = wxProductService.queryProductByOrderandType(productTypeid,"promotion_price");
        }else{
            products = wxProductService.queryProductByOrderandSerach(productSearch,"promotion_price");
        }
        return new Result("200","success",null,products);
        }
    @GetMapping(value="/shop/queryProductByXingPing")
    @ApiOperation(value="根据商品上架时间降序查询",notes ="根据商品上架时间降序查询" )
        public Result queryProductByXingPing(String productSearch,Integer productTypeid){
            List<Product> products=null;
            if(productSearch==null){
                products = wxProductService.queryProductByOrderandType(productTypeid,"product_id desc");
            }else{
                products = wxProductService.queryProductByOrderandSerach(productSearch,"product_id desc");
            }
            return new Result("200","success",null,products);
        }


}
